//
//  ToolUtil.m
//  River
//
//  Created by iMacOne on 15/11/27.
//  Copyright © 2015年 iMacOne. All rights reserved.
//

#import "ToolUtil.h"
#import "AppDelegate.h"

@implementation ToolUtil
#pragma  mark - 字符串宽度

+ (CGFloat)getWidthWithTitle:(NSString *)title font:(UIFont *)font {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1000, 0)];
    label.text = title;
    label.font = font;
    [label sizeToFit];
    return label.frame.size.width;
}
#pragma  mark  一个Lable设置不同颜色和大小
+ (NSAttributedString *)attributeText:(NSString *)leadString color:(UIColor *)leadColor appendString:(NSString *)appendString appendColor:(UIColor *)appendColor attributeFont1:(UIFont *)attributeFont1 attributeFont2:(UIFont *)attributeFont2{
    if (!leadString || !appendString) {
        return [[NSMutableAttributedString alloc] init];
    }
    NSDictionary *attributeLeadColor = @{NSForegroundColorAttributeName:leadColor,NSFontAttributeName:attributeFont1};
    
    NSMutableAttributedString *attributeLeadString = [[NSMutableAttributedString alloc]
                                                      initWithString:leadString
                                                      attributes:attributeLeadColor];
    NSDictionary *attributeAppendColor = @{NSForegroundColorAttributeName:appendColor,NSFontAttributeName:attributeFont2};
    NSAttributedString *attributeAppendString = [[NSAttributedString alloc]
                                                 initWithString:appendString
                                                 attributes:attributeAppendColor];
    [attributeLeadString appendAttributedString:attributeAppendString];
    return attributeLeadString;
}

+ (void)creatAlertControl:(id)viewControl alertString:(NSString *)str
{
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"提示" message:str preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction * enterAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
//        [NSThread sleepForTimeInterval:];
        [viewControl dismissViewControllerAnimated:YES completion:nil];
        
    }];
    [alertController addAction:enterAction];
    [viewControl presentViewController:alertController animated:YES completion:nil];
    
}

+(NSData*)returnDataWithDictionary:(NSDictionary*)dict
{
    NSMutableData* data = [[NSMutableData alloc]init];
    NSKeyedArchiver* archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
    [archiver encodeObject:dict forKey:@"talkData"];
    [archiver finishEncoding];
    
    return data;
}
#pragma mark 获得字符串的字节长度
+ (int)getStrLen:(NSString*)text {
    if ([ToolUtil isBlank:text]) {
        return 0;
    }
    int length = 0;
    for (int i = 0; i < text.length; i++) {
        int ascii = [[text substringWithRange:NSMakeRange(i, 1)] characterAtIndex:0];
        if (ascii >= 0 && ascii <= 255) {
            length++;
        } else {
            length += 2;
        }
    }
    return length;
}

#pragma mark 判断字符串是否为空
+ (BOOL) isBlank:(NSString *)string {
    if (string == nil || string == NULL) {
        return YES;
    }
    string = [string stringByReplacingOccurrencesOfString:@" " withString:@""];
    if (string.length == 0) {
        return YES;
    }
    return NO;
}
+ (void)callPhone:(UIViewController *)control phone:(NSString*)phone
{
    [ToolUtil showOther:control type:@"tel" value:phone];

}
+ (void)showOther:(UIViewController*)control type:(NSString*)type value:(NSString*)value {
    if ([ToolUtil isBlank:type] || [ToolUtil isBlank:value]) {
        return;
    }
    
    UIWebView *callWebview = [[UIWebView alloc] init];
    callWebview.backgroundColor = [UIColor yellowColor];
    NSString *telUrl = [NSString stringWithFormat:@"%@:%@", type, value];
    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:telUrl]]];
    [control.view addSubview:callWebview];
    
}

+ (BOOL)isPhoneNumber:(NSString *)mobileNum
{
    
    NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[06-8])\\d{8}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    
    return [regextestmobile evaluateWithObject:mobileNum];
    
}
+ (float)createLine:(float)y superView:(UIView*)view lift:(float)lift width:(float)width hight:(float)hight color:(UIColor *)color
{
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(lift, y, width, hight)];
    line.backgroundColor = color;
    [view addSubview:line];
    return CGRectGetMaxY(line.frame);
}
+ (float)createVerticalLine:(float)y superView:(UIView*)view lift:(float)lift height:(float)height
{
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(lift, y, 0.5, height)];
    line.backgroundColor = RGBA(223, 223, 223);
    [view addSubview:line];
    return CGRectGetMaxY(line.frame);
    
}
//添加下划线
+ (NSMutableAttributedString *)addHyperLine:(NSString *)content
{
    NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:content];
    NSRange range = {0,[str length]};
    [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:range];
    return str;
}

//自适应高度
+ (CGFloat)customAutoHeigh:(NSString *)contentString width:(CGFloat)width num:(CGFloat)num
{
    CGRect rect = [contentString boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:KFONT(num)} context:nil];
    return rect.size.height;
}
//自适应宽度
+ (CGFloat)autoWidth:(NSString *)nameString width:(CGFloat)width height:(CGFloat)height num:(CGFloat)num
{
    CGSize size = CGSizeMake(width, height);
    //    CGSize labelSize = [nameString sizeWithFont:FONT(num) constrainedToSize:size lineBreakMode:NSLineBreakByWordWrapping];
    CGRect  labelSize = [nameString boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:KFONT(num)} context:nil];
    return labelSize.size.width;
    
}
+ (CGSize)autoWidth1:(NSString *)nameString width:(CGFloat)width height:(CGFloat)height num:(CGFloat)num
{
    CGSize size = CGSizeMake(width, height);
    //    CGSize labelSize = [nameString sizeWithFont:FONT(num) constrainedToSize:size lineBreakMode:NSLineBreakByWordWrapping];
    CGRect  labelSize = [nameString boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:KFONT(num)} context:nil];
    return labelSize.size;
}
+ (NSMutableAttributedString *)labelHeight:(CGFloat)height string:(NSString *)str{
 NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:str];
 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

 [paragraphStyle setLineSpacing:height];//调整行间距

 [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [str length])];

    return attributedString;
}
+ (NSMutableAttributedString *)labelAttributeDict:(NSDictionary *)dic
{
    NSString * labelText = dic[@"labelText"];
    NSString * begin = dic[@"begin"];
    NSString * end = dic[@"end"];
    NSString * textFont = dic[@"textFont"];
    NSString * name = dic[@"Name"];
    NSArray * values = dic[@"values"];
//    NSString * string = NSForegroundColorAttributeName;
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:labelText];
//    NSInteger i = labelText.length;
    [str addAttribute:name value:values[0] range:NSMakeRange(0, str.length)];
    [str addAttribute:name value:values[1] range:NSMakeRange([begin integerValue], [end integerValue])];

//    [str addAttribute:NSForegroundColorAttributeName value:HOME_COLOR range:NSMakeRange([begin integerValue], [end integerValue])];
//
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:[textFont integerValue]] range:NSMakeRange([begin integerValue], [end integerValue])];
//
//    [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:181/255. green:181/255. blue:181/255. alpha:1.0] range:NSMakeRange(i-2, 2)];
    return str;
   
}
#pragma makr - 提示框
+ (void)blackColorLabel:(NSString *)str{
    
    if (str.length ==0) {
        return;
    }
    if ([ToolUtil isBlank:str]) {
        
        return;
    }
    if (![str isKindOfClass:[NSString class]]) {
        
        return;
    }
   
    if ([str containsString:@"参数错误"]) {
        return;
    }
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_W/5, (SCREEN_H-80)/2, SCREEN_W/5*3, 60)];
    view.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
    view.layer.masksToBounds = YES;
    [view.layer setShadowOffset:CGSizeMake(10, 10)]; // 阴影的范围
    view.layer.cornerRadius = 5.0;
    [view.layer setShadowRadius:8]; // 阴影扩散的范围控制
    [view.layer setShadowOpacity:0.7]; // 阴影透明度
    [view.layer setShadowColor:[UIColor colorWithRed:0.7321 green:0.7285 blue:0.7356 alpha:1.0].CGColor]; // 阴影的颜色
    view.layer.shadowPath =  [UIBezierPath bezierPathWithRect:view.bounds].CGPath;
    UILabel*   backLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_W/20, 0, SCREEN_W/2, 60)];
    [view addSubview:backLabel];
    backLabel.text = str;
    backLabel.numberOfLines = 0;
    backLabel.textColor = [UIColor whiteColor];
    backLabel.font = KFONT(14);
    backLabel.textAlignment = NSTextAlignmentCenter;
    AppDelegate *delegate = [UIApplication sharedApplication].delegate;
    [delegate.window addSubview:view];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [backLabel removeFromSuperview];
        [view removeFromSuperview];
    });
}
//画虚线
+ (void)drawingLineFrameLayer:(UIView *)view withFarmeStare:(CGRect)rect{
    
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setBounds:view.bounds];
    [shapeLayer setPosition:view.center];
    [shapeLayer setFillColor:[[UIColor clearColor] CGColor]];
    
    // 设置虚线颜色为
    [shapeLayer setStrokeColor:[[UIColor colorWithRed:223/255.0 green:223/255.0 blue:223/255.0 alpha:1.0f] CGColor]];
    //    [shapeLayer setStrokeColor:[[UIColor blueColor] CGColor]];
    
    // 3.0f设置虚线的宽度
    [shapeLayer setLineWidth:1.0f];//设置虚线的高度
    [shapeLayer setLineJoin:kCALineJoinRound];
    
    // 3=线的宽度 1=每条线的间距
    [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:1],
                                    [NSNumber numberWithInt:1],nil]];
    
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, rect.origin.x,rect.origin.y);//0,100代表初始坐标的x，y
    
    CGPathAddLineToPoint(path, NULL, rect.size.width,rect.size.height);//200,100 代表所画虚线的结束为止的 x,y
    
    [shapeLayer setPath:path];
    CGPathRelease(path);
    // 可以把self改成任何你想要的UIView, 下图演示就是放到UITableViewCell中的
    [[view layer] addSublayer:shapeLayer ];
}

//从十六进制字符串获取颜色，
//color:支持@“#123456”、 @“0X123456”、 @“123456”三种格式
+ (UIColor *)colorWithHexString:(NSString *)color alpha:(CGFloat)alpha {
    //删除字符串中的空格
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    // String should be 6 or 8 characters
    if ([cString length] < 6)
    {
        return [UIColor clearColor];
    }
    // strip 0X if it appears
    //如果是0x开头的，那么截取字符串，字符串从索引为2的位置开始，一直到末尾
    if ([cString hasPrefix:@"0X"])
    {
        cString = [cString substringFromIndex:2];
    }
    //如果是#开头的，那么截取字符串，字符串从索引为1的位置开始，一直到末尾
    if ([cString hasPrefix:@"#"])
    {
        cString = [cString substringFromIndex:1];
    }
    if ([cString length] != 6)
    {
        return [UIColor clearColor];
    }
    
    // Separate into r, g, b substrings
    NSRange range;
    range.location = 0;
    range.length = 2;
    //r
    NSString *rString = [cString substringWithRange:range];
    //g
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    //b
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    // Scan values
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float)r / 255.0f) green:((float)g / 255.0f) blue:((float)b / 255.0f) alpha:alpha];

}

#pragma mark -- 改变获取验证码的颜色
+(void)changeButState:(UIButton *)get withNormTCo:(UIColor*)Nco andSeleCo:(UIColor*)selCo withNoBaGCol:(UIColor*)NorBGCo andSele:(UIColor*)selBgC and:(void (^)(void))timeEnd{
    __block int timeout = 60;  //倒计时时间
    dispatch_queue_t queue = dispatch_get_main_queue();
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0);
    
    dispatch_source_set_event_handler(_timer, ^{
        if(timeout <= 0)
        {
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                get.enabled = YES;
                get.backgroundColor = NorBGCo;
                [get setTitleColor:Nco forState:UIControlStateNormal];
                [get setTitle:@"重新获取" forState:UIControlStateNormal];
                dispatch_suspend(_timer);
            });
            
            if (timeEnd) {
                timeEnd();
            }
            
        }
        else
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                get.enabled = NO;
                [get setTitleColor:selCo forState:UIControlStateNormal];
                get.backgroundColor = selBgC;
                [get setTitle:[NSString stringWithFormat:@"%d秒后发送", timeout]forState:UIControlStateNormal];
            });
            timeout--;
        }
    }); //;
    dispatch_resume(_timer);
    

}

+ (void)countDownWithTime:(int)time
           countDownBlock:(void (^)(int timeLeft))countDownBlock
                 endBlock:(void (^)())endBlock
{
    __block int timeout = time; //倒计时时间
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
    dispatch_source_set_event_handler(_timer, ^{
        if(timeout<=1){ //倒计时结束，关闭
            dispatch_source_cancel(_timer);
            dispatch_async(dispatch_get_main_queue(), ^{
                if (endBlock) {
                    endBlock();
                }
            });
        } else {
            dispatch_async(dispatch_get_main_queue(), ^{
                timeout--;
                if (countDownBlock) {
                    countDownBlock(timeout);
                }
            });
        }
    });
    dispatch_resume(_timer);
}


//#pragma mark -- 得到转换之后的签名
//+(NSString * )getOrderString:(NSDictionary *)parDiect  {
//    
//    Order *order = [[Order alloc] init];
//    
//    order.partner = [parDiect valueForKeyPath:@"partner"];
//    
//    order.sellerID = [NSString stringWithFormat:@"%@",[parDiect valueForKeyPath:@"seller_id"]];
//    order.outTradeNO = [NSString stringWithFormat:@"%@",[parDiect valueForKeyPath:@"out_trade_no"]]; //订单ID（由商家自行制定）
//    order.subject = [parDiect valueForKeyPath:@"subject"]; //product.subject; //商品标题
//    order.body = [parDiect valueForKeyPath:@"body"];//product.body; //商品描述
//    order.totalFee = [parDiect valueForKeyPath:@"total_fee"]; //商品价格
//    order.notifyURL = [parDiect valueForKeyPath:@"notify_url"]; //回调URL
//    
//    order.service = [parDiect valueForKeyPath:@"service"];
//    order.paymentType = [NSString stringWithFormat:@"%@",[parDiect valueForKeyPath:@"payment_type"]];
//    order.inputCharset = [parDiect objectForKey:@"_input_charset"];
//    
//    //将商品信息拼接成字符串(签名)
//    
//    NSString *orderSpec = [order description];
//    NSLog(@"orderSpec = %@",orderSpec);
//    
//    return orderSpec;
//}



+ (BOOL)isValidateEmail:(NSString *)email

{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES%@",emailRegex];
    
    return [emailTest evaluateWithObject:email];
    
}

+ (BOOL)isCorrect:(NSString *)IDNumber
{
    
     if (IDNumber.length != 18) return NO;
    
    NSMutableArray *IDArray = [NSMutableArray array];
    // 遍历身份证字符串,存入数组中
    for (int i = 0; i < 18; i++) {
        NSRange range = NSMakeRange(i, 1);
        NSString *subString = [IDNumber substringWithRange:range];
        [IDArray addObject:subString];
    }
    // 系数数组
    NSArray *coefficientArray = [NSArray arrayWithObjects:@"7", @"9", @"10", @"5", @"8", @"4", @"2", @"1", @"6", @"3", @"7", @"9", @"10", @"5", @"8", @"4", @"2", nil];
    // 余数数组
    NSArray *remainderArray = [NSArray arrayWithObjects:@"1", @"0", @"X", @"9", @"8", @"7", @"6", @"5", @"4", @"3", @"2", nil];
    // 每一位身份证号码和对应系数相乘之后相加所得的和
    int sum = 0;
    for (int i = 0; i < 17; i++) {
        int coefficient = [coefficientArray[i] intValue];
        int ID = [IDArray[i] intValue];
        sum += coefficient * ID;
    }
    // 这个和除以11的余数对应的数
    NSString *str = remainderArray[(sum % 11)];
    // 身份证号码最后一位
    NSString *string = [IDNumber substringFromIndex:17];
    // 如果这个数字和身份证最后一位相同,则符合国家标准,返回YES
    if ([str isEqualToString:string]) {
        return YES;
    } else {
        return NO;
    }
}

+(NSString *)getCurrentTiem; {
    
    NSDate *  senddate=[NSDate date];
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYYMMdd"];
    NSString * location =[dateformatter stringFromDate:senddate];
    return location;
}



+ (NSString * )getCurrentTimer
{
    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"HHmmss"];
    
//    NSLog(@"当前时间:%d",[[dateFormatter stringFromDate:currentDate] intValue]);
    
    return  [dateFormatter stringFromDate:currentDate];
}


+(NSArray *)setPickerData{
    
    NSMutableArray * dataArr = [[NSMutableArray alloc]initWithCapacity:0];
    [dataArr addObject:@"今天"];
    [dataArr addObject:@"明天"];
    [dataArr addObject:@"后天"];
    
    for (int i = 3 ; i< 7; i++) {
        NSTimeInterval interval = 60 * 60 * 24*i; //秒数
        
        NSDate * currDate=[NSDate dateWithTimeIntervalSinceNow:interval];
        
        NSString *str = [NSString stringWithFormat:@"%@",[self getNowDateFromatAnDate:currDate]];
        NSString * str1= [str substringToIndex:10];
        NSString * weekDay = [self weekdayStringFromDate:[self getNowDateFromatAnDate:currDate]];
        
        NSString * str2 = [[str1 substringFromIndex:5] substringToIndex:5];
        NSArray * monthArr = [str2 componentsSeparatedByString:@"-"];
        NSString * currMonth;
        if ([monthArr[0] integerValue]<10) {
            NSString * monthStr = [[monthArr[0] substringFromIndex:1] substringToIndex:1];
            currMonth = [NSString stringWithFormat:@"%@-%@ %@",monthStr,monthArr[1],weekDay];
        }else{
            currMonth = [NSString stringWithFormat:@"%@ %@",str2,weekDay];
        }
        [dataArr addObject:currMonth];
    }
    return dataArr;
    //    NSArray * dataArr = @[@"今天",@"明天",@"后台",@"",@"",@"",@""];
    
}
+ (NSString*)weekdayStringFromDate:(NSDate*)inputDate {
    
    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"周日", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六", nil];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/BeiJing"];
    
    [calendar setTimeZone: timeZone];
    
    NSCalendarUnit calendarUnit = NSCalendarUnitWeekday;
    
    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];
    
    return [weekdays objectAtIndex:theComponents.weekday];
    
}
+ (NSDate *)getNowDateFromatAnDate:(NSDate *)anyDate
{
    //设置源日期时区
    NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];//或GMT
    //设置转换后的目标日期时区
    NSTimeZone* destinationTimeZone = [NSTimeZone localTimeZone];
    //得到源日期与世界标准时间的偏移量
    NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:anyDate];
    //目标日期与本地时区的偏移量
    NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:anyDate];
    //得到时间偏移量的差值
    NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
    //转为现在时间
    NSDate* destinationDateNow = [[NSDate alloc] initWithTimeInterval:interval sinceDate:anyDate];
    return destinationDateNow;
}

+ (void)showMobileAlert:(NSString *)titleString withMessage:(NSString *)message withController:(UIViewController *)controller {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:titleString message:message preferredStyle:(UIAlertControllerStyleAlert)];
    
    UIAlertAction * enterAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        [alertController dismissViewControllerAnimated:YES completion:nil];
        NSString *mobileString = [NSString stringWithFormat:@"tel://%@",message];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mobileString]];
    }];
    [alertController addAction:enterAction];
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];
    [alertController addAction:cancelAction];
    
    
    [controller presentViewController:alertController animated:YES completion:nil];
}


@end
